#include "CONFIG.H"
#include "BUZZER.H"
#include "DELAY.H"

#define	L1	1
#define	L2	2
#define	L3	3
#define	L4	4
#define	L5	5
#define	L6	6
#define	L7	7

#define N0 0

#define	N1	L1 + 7
#define	N2	L2 + 7
#define	N3	L3 + 7
#define	N4	L4 + 7
#define	N5	L5 + 7
#define	N6	L6 + 7
#define	N7	L7 + 7

#define	H1	N1 + 7
#define	H2	N2 + 7
#define	H3	N3 + 7
#define	H4	N4 + 7
#define	H5	N5 + 7
#define	H6	N6 + 7
#define	H7	N7 + 7


u8 code notes[] = {
    N6, N7, 			       H1, N7, H1, H3, 	    N7, N3, N3, 			    N6, N5, N6, H1, 		     N5, N0, N3, N3,		  N4, N3, N4, H1,
    N3, N0, H1, H1, H1,  N7, N4, N4, N7,	    N7, N0, N6, N7, 		  H1, N7, H1, H3,			     N7, N0, N3, N3,		  N6, N5, N6, H1,
    N5, N0, N3, 		     N4, H1, N7, N7, H1,  H2, H2, H3, H1, N0,   H1, N7, N6, N6, N7, N5,	 N6, N0, H1, H2,	  	H3, H2, H3, H5,
    H2, N0, N5,	N5,		   H1, N7, H1, H3,	    H3, N0, N0,			      N6, N7, H1, N7, H2, H2,  H1, N5, N5, N0,		  H4, H3, H2, H1,
    H3, 		 		         H3, N0, H3,		      H6, H5, H5,			      H3, H2, H1, N0, H1, 	   H2, H1, H2, H2, H5, 	H3, N0, H3,
    H6,	H5,				       H3, H2, H1, N0, H1,  H2, H1, H2, H2, N7,   N6, N0, 
};

u8 code durations[] = {
    2, 2, 				   6, 2, 4, 4, 		   12, 2, 2, 			    6, 2, 4, 4, 			  8, 4, 2, 2,				6, 2, 2, 6,
    8, 2, 2, 2, 2, 	 6, 2, 4, 4,			  8, 4, 2, 2, 			6, 2, 4, 4,				  8, 4, 2, 2,				6, 2, 4, 4,
    12, 2, 2, 			 4, 2, 2, 4, 4,		  2, 2, 2, 4, 4, 		4, 2, 2, 2, 4, 4,		8, 4, 2, 2,				6, 2, 4, 4,
    8, 4, 2, 2,			 2, 2, 4, 4,			  8, 4, 4,				  2, 2, 4, 4, 2, 2, 	6, 2, 4, 4,				4, 4, 4, 4,
    16, 				     8, 4,	4,			    8, 4, 4,				  2, 2, 4, 2, 2, 			4, 2, 2, 2, 4, 		8, 4, 4,
    8, 8,				     2, 2, 8, 2, 2, 		4, 2, 2, 2, 4, 	 	8, 4, 
};

void main(){
	u8 len = sizeof(notes) / sizeof(notes[0]);
	u8 i;
	u16 delay;
	
	Buzzer_start();
	
	EA = 1;
	
	for(i = 0;i < len;i++){
		
		Buzzer_been(notes[i]);
		delay = durations[i] * 100;
		
		delay_X_ms(delay);
		Buzzer_stop();
		delay_ms(20);
	}
	Buzzer_stop();
	
	
	while(1){

	}
}